package com.ruoyi.web.controller.pay;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.pay.domain.po.PayRefund;
import com.ruoyi.system.pay.domain.dto.RefundRequestDTO;
import com.ruoyi.system.pay.service.IRefundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 退款控制器
 */
@RestController
@RequestMapping("/api/refund")
public class RefundController {

    @Autowired
    private IRefundService refundService;

    /**
     * 申请退款
     *
     * @param orderNumber  订单号
     * @param refundAmount 退款金额
     * @return 退款申请结果
     */
    @PostMapping("/apply")
    public AjaxResult requestRefund(@RequestParam String orderNumber,
                                    @RequestParam Double refundAmount) {
//        try {
//            String result = refundService.requestRefund(orderNumber, refundAmount);
//            return AjaxResult.success(result);
//        } catch (Exception e) {
//            return AjaxResult.error("退款申请失败: " + e.getMessage());
//        }
        return AjaxResult.success();
    }

    /**
     * 查询退款状态
     *
     * @param refundId 退款 ID
     * @return 退款详情
     */
    @GetMapping("/status")
    public AjaxResult getRefundStatus(@RequestParam Long refundId) {
        PayRefund refund = refundService.getRefundStatus(refundId);
        return refund != null ? AjaxResult.success(refund) : AjaxResult.error("退款记录不存在");
    }

    /**
     * 统一退款接口
     */
    @PostMapping("/unified")
    public String unifiedRefund(@RequestBody RefundRequestDTO refundRequestDTO) {
//        return refundService.unifiedRefund(refundRequestDTO);
        return "test";
    }
}
